package com.foreveredu.erlms.web.struts.action;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.beanutils.PropertyUtils;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.foreveredu.erlms.domain.News;
import com.foreveredu.erlms.domain.PageModel;
import com.foreveredu.erlms.domain.Role;
import com.foreveredu.erlms.domain.Teacher;
import com.foreveredu.erlms.domain.User;
import com.foreveredu.erlms.service.IManagementService;
import com.foreveredu.erlms.web.struts.actionform.NewsActionForm;

public class NewsAction extends AbstractBaseDispatchAction {

	private IManagementService managementService = null;

	public IManagementService getManagementService() {
		return managementService;
	}

	public void setManagementService(IManagementService managementService) {
		this.managementService = managementService;
	}

	// 首页公告列表
	public ActionForward newsListView(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		List<News> news = managementService.findNewsListView();
		request.setAttribute("newsList", news);
		return mapping.findForward("newsListView");
	}

	// 通过ID查找公告详情
	public ActionForward findNewsById(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		NewsActionForm newsform = (NewsActionForm) form;
		News news = managementService.findNewsById(newsform.getId());
		request.setAttribute("news", news);
		news.setTotal(news.getTotal()+1);
		managementService.updateNews(news);
		return mapping.findForward("findNewsById");
	}

	//首页显示公告详情（通过state）
	public ActionForward showNewsByState(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		News news = managementService.findNewsByState();
		request.setAttribute("news", news);
		return mapping.findForward("showNewsByState");
	}
}
